import java.util.concurrent.locks.ReentrantLock;

public class Bank implements Runnable {
    private Bank(){}
    private static Bank bank=null;
    public static synchronized Bank getAccount(){
        if(bank==null)
            bank=new Bank();
        return bank;
    }
    private int money=0;
    private boolean isFull=false;
    private ReentrantLock lock=new ReentrantLock(true);
    private void saving(){
            lock.lock();
            if(money<30000)
                try {
                    money+=1000;
                    System.out.println(Thread.currentThread().getName()+"存钱，"+"账户余额："+money+"元");
                } finally {
                    lock.unlock();
                }

            else
                isFull=true;
    }
    @Override
    public void run() {
        while(!isFull){
            saving();
        }
    }
}
